package subject_set.lc200;

import java.util.LinkedList;
import java.util.List;

/**
 * @author haomin
 * @date 2022/12/16 23:27
 **/
public class Num17 {
    class Solution {
        public char[][] letters = new char[][]{{}, {}, {'a','b','c'},{'d','e','f'},{'g','h','i'},{'j','k','l'},{'m','n','o'},{'p','q','r','s'},{'t','u','v'},{'w','x','y','z'}};
        List<String> res = new LinkedList<>();

        public List<String> letterCombinations(String digits) {
            dfs(digits.toCharArray(),0, new StringBuffer());
            return res;
        }

        public void dfs(char[] strs, int p, StringBuffer sb) {
            if (p == strs.length) {
                res.add(sb.toString());
                return;
            }
            int num = strs[p] - '0';
            for (int i = 0; i < letters[num].length; ++i) {
                sb.append(letters[num][i]);
                dfs(strs, p + 1, sb);
                sb.deleteCharAt(sb.length() - 1);
            }
        }
    }
}